package com.soufang.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;

import com.zxx.adapter.TestAdapter;
import com.zxx.pullRefresh.MyListener;
import com.zxx.pullRefresh.PullToRefreshLayout;
import com.zxx.pullRefresh.PullableListView;

/**
 * @brief 上拉下拉控件测试页面
 * @author zxx
 * 
 */
public class googlePullFragment extends Fragment {
		
	private PullableListView pullableListView;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View contextView = inflater.inflate(R.layout.googlepull_fragment, container, false);
		
		PullToRefreshLayout rootLayout = ((PullToRefreshLayout) contextView.findViewById(R.id.refresh_view));
		rootLayout.setOnRefreshListener(new MyListener());
		
		pullableListView =  (PullableListView)contextView.findViewById(R.id.content_view);
		initListView();
		return contextView;
	}

	private void initListView()
	{
		List<String> items = new ArrayList<String>();
		for (int i = 0; i < 30; i++)
		{
			items.add("这里是item " + i);
		}
		TestAdapter adapter = new TestAdapter(getActivity(), items);
		pullableListView.setAdapter(adapter);
		pullableListView.setOnItemLongClickListener(new OnItemLongClickListener()
		{

			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id)
			{
				Toast.makeText(
						getActivity(),
						"LongClick on "
								+ parent.getAdapter().getItemId(position),
						Toast.LENGTH_SHORT).show();
				return true;
			}
		});
		pullableListView.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id)
			{
				Toast.makeText(getActivity(),
						" Click on " + parent.getAdapter().getItemId(position),
						Toast.LENGTH_SHORT).show();
			}
		});
	}
}
